//============================================================================================
/**
 *	@file	d_nagi.c
 *	@brief	名木橋用デバッグメニュー
 *
 *	@date	08/06/13
 *	@author	Toru=Nagihashi
 */
//============================================================================================

#ifdef PM_DEBUG

#include "common.h"

#include "system/lib_pack.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "fld_bmp.h"
#include "fieldmap.h"
#include "fieldsys.h"
#include "fieldmap_work.h"
#include "system/fontproc.h"
#include "system/window.h"
#include "system/numfont.h"
#include "system/arc_util.h"
#include "system/snd_tool.h"
#include "system/snd_system.h"

#include "d_nagi.h"
#include "msgdata/msg_debug_nagi.h"
#include "msgdata/msg.naix"

#include "system/touchpanel_draw.h"
#include "field_light.h"
#include "field_glb_state.h"
#include "talk_msg.h"

#include "script.h"

#include "encount_effect.h"
#include "system/wipe.h"


#include "application/mictest.h"
#include "d_nagi_local.h"

//=============================================================================
/**
 *		define
 */
//=============================================================================
#define NAGI_PRINT(...)					NAGIHASHI_PRINT(__VA_ARGS__)
#define NAGI_NULL_ASSERT(x)				GF_ASSERT(x!=NULL)
#define NAGI_MINMAX_ASSERT(x,min,max)	GF_ASSERT(min<=x&&x<max)
#define NAGI_ROUND(x,min,max)			( (x) < (min) ) ? (max): ( (x) > (max) ) ? (min) : (x) ;//	回り込みの値を返す（3, 5, 10）なら10を返す

//=============================================================================
/**
 *		struct
 */
//=============================================================================
//-------------------------------------
///		ウィンドウの文字と実行関数
//=====================================
typedef struct
{
	u32  str_id;
	u32  param;
}LIST_PARAM;

//-------------------------------------
///		デバッグウィンドウの情報
//=====================================
typedef struct {
	u16 debug_list;
	u16 debug_cursor;

	GF_BGL_BMPWIN		win;
	BMPLIST_WORK		*lw;		// BMPメニューワーク
	BMP_MENULIST_DATA 	*ld;
}DEBUG_WINDOW_DATA;

//-------------------------------------
///		文字描画用テーブル
//=====================================
typedef struct {
	u32 str_id;	//	フォントID	もしくは　テーブル終了コード
	u32	x;
	u32 y;
}DEBUG_BMPWIN_STRPRINT_TBL;
#define DEBUG_BMPWIN_STRPRINT_END	(0xFFFFFFFF)	//	テーブル終了コード

//=============================================================================
/**
 *		デバッグウィンドウ関係
 */
//=============================================================================
//	リスト用ウィンドウ作成用
static void MakeBmpList(int inNum, const LIST_PARAM *list, const BMPWIN_DAT *win_dat);
static void	MoveLineCallBack(BMPLIST_WORK* lw,u32 param,u8 y);
static void InitDebugWindow(DEBUG_WINDOW_DATA *wp);
static void DebugListFree(TCB_PTR tcb,void* work);
static void DebugWindowExit(TCB_PTR tcb,void* work);
static void DebugListControlTask(TCB_PTR tcb,void* work);

//	文字描画用ウィンドウ作成用
static void MakeBmpWin( GF_BGL_BMPWIN *p_bmpwin, const BMPWIN_DAT *p_dat );
static void EndBmpWin( GF_BGL_BMPWIN *p_bmpwin );
static void PrintStrBmpWin( GF_BGL_BMPWIN* win, const DEBUG_BMPWIN_STRPRINT_TBL *p_tbl );
static void PrintNumBmpWin(  GF_BGL_BMPWIN* win, s32 num, u32 x, u32 y );
static void ClearRangeBmpWin( GF_BGL_BMPWIN* win, u32 x, u32 y  );

//=============================================================================
//
///	項目ごと
//
//=============================================================================
//-----------------------------------------------------------------------------
//		エンカウントエフェクト
//-----------------------------------------------------------------------------
//-------------------------------------
//	エンカウントエフェクト管理ワーク
//=====================================
typedef struct {
	s32 no;
	u32 seq;
	u32 end;
	BOOL sub_end;
	u16 now_bgm;
	s32 work[2];
} D_NAGI_ENCOUNT_SYS_WORK;
static void StartEncountEffectSys( u32 effect_no );
static void MainEncountEffectSys( TCB_PTR tcb, void* p_work );
static void SetEncountDebugWindow(TCB_PTR tcb,void *work);

//-------------------------------------
///	エンカウントエフェクト管理ワーク＋終了エフェクト指定
//=====================================
static void EffectEnd_StartFadeIn( void *p_adrs );
static BOOL EffectEnd_MainFadeIn( void *p_adrs );

static const struct {
	void (*Init)(void*);
	BOOL (*Main)(void*);
} EffectEndFunc[]	= {
	{ EffectEnd_StartFadeIn, EffectEnd_MainFadeIn},
};
typedef enum {
	EFFECT_END_FADEIN,
}EFFECT_END_TYPE;
static void StartEncountEffectSysWithFinish( u32 effect_no, EFFECT_END_TYPE end_type );
static void MainEncountEffectSysWithFinish( TCB_PTR tcb, void* p_work );

// 各ｴﾌｪｸﾄ
static void EncountEffect_00( TCB_PTR tcb, void* p_work );
static void EncountEffect_01( TCB_PTR tcb, void* p_work );
static void EncountEffect_02( TCB_PTR tcb, void* p_work );
static void EncountEffect_03( TCB_PTR tcb, void* p_work );
static void EncountEffect_04( TCB_PTR tcb, void* p_work );
static void EncountEffect_05( TCB_PTR tcb, void* p_work );
static void EncountEffect_06( TCB_PTR tcb, void* p_work );
static void EncountEffect_07( TCB_PTR tcb, void* p_work );
static void EncountEffect_08( TCB_PTR tcb, void* p_work );
static void EncountEffect_09( TCB_PTR tcb, void* p_work );
static void EncountEffect_10( TCB_PTR tcb, void* p_work );
static void EncountEffect_11( TCB_PTR tcb, void* p_work );
static void EncountEffect_12( TCB_PTR tcb, void* p_work );
static void EncountEffect_13( TCB_PTR tcb, void* p_work );
static void EncountEffect_14( TCB_PTR tcb, void* p_work );
static void EncountEffect_15( TCB_PTR tcb, void* p_work );
static void EncountEffect_16( TCB_PTR tcb, void* p_work );
static void EncountEffect_17( TCB_PTR tcb, void* p_work );
static void EncountEffect_18( TCB_PTR tcb, void* p_work );
static void EncountEffect_19( TCB_PTR tcb, void* p_work );
static void EncountEffect_20( TCB_PTR tcb, void* p_work );
static void EncountEffect_21( TCB_PTR tcb, void* p_work );
static void EncountEffect_22( TCB_PTR tcb, void* p_work );
static void EncountEffect_23( TCB_PTR tcb, void* p_work );
static void EncountEffect_24( TCB_PTR tcb, void* p_work );
static void EncountEffect_25( TCB_PTR tcb, void* p_work );
static void EncountEffect_26( TCB_PTR tcb, void* p_work );
static void EncountEffect_27( TCB_PTR tcb, void* p_work );
static void EncountEffect_28( TCB_PTR tcb, void* p_work );
static void EncountEffect_29( TCB_PTR tcb, void* p_work );
static void EncountEffect_30( TCB_PTR tcb, void* p_work );
static void EncountEffect_31( TCB_PTR tcb, void* p_work );
static void EncountEffect_32( TCB_PTR tcb, void* p_work );
static void EncountEffect_33( TCB_PTR tcb, void* p_work );
static void EncountEffect_34( TCB_PTR tcb, void* p_work );
static void EncountEffect_35( TCB_PTR tcb, void* p_work );
static void EncountEffect_36( TCB_PTR tcb, void* p_work );
static void EncountEffect_37( TCB_PTR tcb, void* p_work );
static void EncountEffect_38( TCB_PTR tcb, void* p_work );
static void EncountEffect_39( TCB_PTR tcb, void* p_work );
static void EncountEffect_40( TCB_PTR tcb, void* p_work );
static void EncountEffect_41( TCB_PTR tcb, void* p_work );
static void EncountEffect_42( TCB_PTR tcb, void* p_work );
static void EncountEffect_43( TCB_PTR tcb, void* p_work );
static void EncountEffect_44( TCB_PTR tcb, void* p_work );
static void EncountEffect_45( TCB_PTR tcb, void* p_work );
static void EncountEffect_46( TCB_PTR tcb, void* p_work );
static void EncountEffect_47( TCB_PTR tcb, void* p_work );
static void EncountEffect_48( TCB_PTR tcb, void* p_work );
static void EncountEffect_49( TCB_PTR tcb, void* p_work );

//=============================================================================
//		前選んだ命令
//=============================================================================
static void StartPreCommand( TCB_PTR tcb,void* work );
static void SetPreCommand( TCB_FUNC func );


//=============================================================================
//		手書き再現用
//=============================================================================
//-------------------------------------
///	手書き再現用文字列データ
//=====================================
static const DEBUG_BMPWIN_STRPRINT_TBL	HandDrawDebugStr[]	= {
	{ MSG_HANDDRAW_01,
		0,
		0,
	},
	{
		DEBUG_BMPWIN_STRPRINT_END
	},
};
//-------------------------------------
///手書き再現用ワーク
//=====================================
typedef struct {
	GF_BGL_BMPWIN		bmpwin;
	s32					seq;
	u32					idx;
} D_NAGI_HANDDRAW_WORK;

//-------------------------------------
///	手書き再現ワーク
//=====================================
ENC_HAND_DRAW_POS_TBL g_debug_enc_draw_pos_tbl[HAND_DRAW_TBL_MAX]	= {{0xFF, 0xFF}};

static void StartHandDraw( TCB_PTR tcb, void* p_work );
static void MainHandDraw( TCB_PTR tcb, void* p_work );

//=============================================================================
//		ワイプチェック
//=============================================================================
//-------------------------------------
//	ワイプチェックタスク構造体
//=====================================
typedef struct{
	int no;		// ワイプナンバー
	int seq;
}D_TMY_WIPE;

//-----------------------------------------------------------------------------
//			プロトタイプ
//-----------------------------------------------------------------------------
static void StartWipe( TCB_PTR tcb,void* work );		// 画面切り替え開始
static void MainWipe( TCB_PTR tcb,void* work );			// 画面切り替えメイン


//=============================================================================
//		曲同期
//=============================================================================
//-------------------------------------
///	曲同期用文字列データ
//=====================================
static const DEBUG_BMPWIN_STRPRINT_TBL	BgmSyncDebugStr[]	= {
	{ MSG_MUSICSYNC_00,
		0,
		0,
	},
	{
		DEBUG_BMPWIN_STRPRINT_END
	},
};

//-------------------------------------
///	曲同期用ワーク
//=====================================
typedef struct {
	GF_BGL_BMPWIN		bmpwin;
	s16					sync_no;
	s16					bgm_no;
	s8					array_no;
	u8					is_bgmplay;
} D_NAGI_BGMSYNC_WORK;
//-----------------------------------------------------------------------------
//			プロトタイプ
//-----------------------------------------------------------------------------
static void StartBgmTiming( TCB_PTR p_tcb, void * p_work );
static void MainBgmTiming( TCB_PTR p_tcb, void * p_work );



//=============================================================================
//		アプリケーション
//=============================================================================
static D_NAGI_APPLICATION_WORK* APPLICATION_AllocWork( int heap_id, u32 param_size );

//-------------------------------------
///		mictest
//=====================================
static void MicTest_SetProc( void * work );
static void CallMicTest( TCB_PTR p_tcb, void *p_wk );

//-------------------------------------
///		stage
//=====================================
static void CallFrontierStage( TCB_PTR tcb,void* work );

static void CallFrontierCastle( TCB_PTR tcb,void* work );

static void CallFrontierFactoryR( TCB_PTR tcb,void* work );
static void CallFrontierFactoryC( TCB_PTR tcb,void* work );

//=============================================================================
//
///	ウィンドウのデータ
//
//=============================================================================
//-------------------------------------
///		ウィンドウの範囲情報など
//=====================================
//	メインウィンドウ
static const BMPWIN_DAT	MainDebugListWindowData = {
	FLD_MBGFRM_FONT,
	0,0,
	16,24,
	FLD_SYSFONT_PAL,
	8
};
//	エンカウント用
static const BMPWIN_DAT	EncountDebugListWindowData = {
	FLD_MBGFRM_FONT,
	0,0,
	16,24,
	FLD_SYSFONT_PAL,
	8
};
//	曲同期用
static const BMPWIN_DAT	BgmSyncDebugStrWindowData = {
	FLD_MBGFRM_FONT,
	2,2,
	28,20,
	FLD_SYSFONT_PAL,
	8
};



//-------------------------------------
///		ウィンドウの項目
//=====================================
//	メインウィンドウ
static const LIST_PARAM MainDebugList[] = {

#ifndef GS_DEBUG_OFF
	{MSG_LABEL_UTIL, BMPLIST_RABEL},
	{MSG_RECOMMAND, (u32)StartPreCommand},

	{MSG_LABEL_EFF, BMPLIST_RABEL},
	{MSG_WIPE,(u32)StartWipe},
	{MSG_ENCOUNT,(u32)SetEncountDebugWindow},

	{MSG_LABEL_TOOL, BMPLIST_RABEL},
	{MSG_BGMTIMING, (u32)StartBgmTiming},
	{MSG_HANDDRAW, (u32)StartHandDraw},
#endif
	{MSG_LABEL_APP, BMPLIST_RABEL},
	{MSG_MICTEST, (u32)CallMicTest},
	{MSG_STAGE, (u32)CallFrontierStage},
	{MSG_CASTLE, (u32)CallFrontierCastle},
	{MSG_FACTORY_R, (u32)CallFrontierFactoryR},
	{MSG_FACTORY_C, (u32)CallFrontierFactoryC},
};


#ifndef GS_DEBUG_OFF
//	エンカウント用
static const LIST_PARAM SubEncountDebugList[] = {	// エンカウントエフェクト
	{MSG_LABEL_DP, BMPLIST_RABEL},
	{MSG_ENCOUNT_SUB00,(u32)EncountEffect_00},
	{MSG_ENCOUNT_SUB01,(u32)EncountEffect_01},
	{MSG_ENCOUNT_SUB02,(u32)EncountEffect_02},
	{MSG_ENCOUNT_SUB03,(u32)EncountEffect_03},
	{MSG_ENCOUNT_SUB04,(u32)EncountEffect_04},
	{MSG_ENCOUNT_SUB05,(u32)EncountEffect_05},
	{MSG_ENCOUNT_SUB06,(u32)EncountEffect_06},
	{MSG_ENCOUNT_SUB07,(u32)EncountEffect_07},
	{MSG_ENCOUNT_SUB08,(u32)EncountEffect_08},
	{MSG_ENCOUNT_SUB09,(u32)EncountEffect_09},
	{MSG_ENCOUNT_SUB10,(u32)EncountEffect_10},
	{MSG_ENCOUNT_SUB11,(u32)EncountEffect_11},
	{MSG_ENCOUNT_SUB12,(u32)EncountEffect_12},
	{MSG_ENCOUNT_SUB13,(u32)EncountEffect_13},
	{MSG_ENCOUNT_SUB14,(u32)EncountEffect_14},
	{MSG_ENCOUNT_SUB15,(u32)EncountEffect_15},
	{MSG_ENCOUNT_SUB16,(u32)EncountEffect_16},
	{MSG_ENCOUNT_SUB17,(u32)EncountEffect_17},
	{MSG_ENCOUNT_SUB18,(u32)EncountEffect_18},
	{MSG_ENCOUNT_SUB19,(u32)EncountEffect_19},
	{MSG_ENCOUNT_SUB20,(u32)EncountEffect_20},
	{MSG_ENCOUNT_SUB21,(u32)EncountEffect_21},
	{MSG_ENCOUNT_SUB22,(u32)EncountEffect_22},
	{MSG_ENCOUNT_SUB23,(u32)EncountEffect_23},
	{MSG_ENCOUNT_SUB24,(u32)EncountEffect_24},
	{MSG_ENCOUNT_SUB25,(u32)EncountEffect_25},
	{MSG_ENCOUNT_SUB26,(u32)EncountEffect_26},
	{MSG_ENCOUNT_SUB27,(u32)EncountEffect_27},
	{MSG_ENCOUNT_SUB28,(u32)EncountEffect_28},
	{MSG_ENCOUNT_SUB29,(u32)EncountEffect_29},
	{MSG_ENCOUNT_SUB30,(u32)EncountEffect_30},
	{MSG_TEST, (u32)EncountEffect_31},

	{MSG_LABEL_GS, BMPLIST_RABEL},
	{MSG_ENCOUNT_SUB31, (u32)EncountEffect_32},
	{MSG_ENCOUNT_SUB32, (u32)EncountEffect_33},
	{MSG_ENCOUNT_SUB33, (u32)EncountEffect_34},
	{MSG_ENCOUNT_SUB34, (u32)EncountEffect_35},
	{MSG_ENCOUNT_SUB35, (u32)EncountEffect_36},
	{MSG_ENCOUNT_SUB36, (u32)EncountEffect_37},
	{MSG_ENCOUNT_SUB37, (u32)EncountEffect_38},
	{MSG_ENCOUNT_SUB38, (u32)EncountEffect_39},
	{MSG_ENCOUNT_SUB39, (u32)EncountEffect_40},
	{MSG_ENCOUNT_SUB40, (u32)EncountEffect_41},
	{MSG_ENCOUNT_SUB41, (u32)EncountEffect_42},
	{MSG_ENCOUNT_SUB42, (u32)EncountEffect_43},
	{MSG_ENCOUNT_SUB43, (u32)EncountEffect_44},
	{MSG_ENCOUNT_SUB44, (u32)EncountEffect_45},
	{MSG_ENCOUNT_SUB45, (u32)EncountEffect_46},
	{MSG_ENCOUNT_SUB46, (u32)EncountEffect_47},
	{MSG_ENCOUNT_SUB47, (u32)EncountEffect_48},
	{MSG_ENCOUNT_SUB48, (u32)EncountEffect_49},
};
#endif

static FIELDSYS_WORK	* sp_fldsys		= NULL;
static TCB_FUNC			sp_PreCommand	= NULL;
//=============================================================================
/**
 *		デバッグメニュー開始
 */
//=============================================================================
//----------------------------------------------------------------------------
/**
 *	@brief	名木橋用デバッグメニュー開始（fld_debug.cから呼ばれる）
 *
 *	@param	p_fldsys	フィールドワーク
 *
 *	@return	none
 */
//-----------------------------------------------------------------------------
void DebugNagiMenuInit(FIELDSYS_WORK* p_fldsys)
{
	sp_fldsys	= p_fldsys;
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
}

//=============================================================================
//	ウィンドウ設定
//=============================================================================
//リスト作成
static void MakeBmpList( int inNum, const LIST_PARAM *list, const BMPWIN_DAT * win_dat )
{
	TCB_PTR pTcb;
	DEBUG_WINDOW_DATA *wp;

	BMPLIST_HEADER bmplist_h = {
		//MainDebugList,	//表示文字データポインタ
		NULL,				//表示文字データポインタ
		NULL,				//カーソル移動ごとのコールバック関数
		MoveLineCallBack,	//１行ごとのコールバック関数
		NULL,				//GF_BGL_BMPWIN *
		0,					//リスト項目数
		0,					//表示最大項目数
		2,					//ラベル表示Ｘ座標
		12,					//項目表示Ｘ座標
		1,					//カーソル表示Ｘ座標
		8,					//表示Ｙ座標
		FBMP_COL_WHITE,		//文字色
		FBMP_COL_BLACK,		//背景色
		FBMP_COL_BLK_SDW,	//文字影色
		0,					//文字間隔Ｘ
		1,					//文字間隔Ｙ
		BMPLIST_LRKEY_SKIP,	//ページスキップタイプ
		FONT_SYSTEM,		//文字指定
		0,					//ＢＧカーソル(allow)表示フラグ(0:ON,1:OFF)
		NULL,				//*work
	};

	wp = sys_AllocMemory(HEAPID_FIELD,sizeof(DEBUG_WINDOW_DATA));
	if(wp == NULL){
		//ワークエリアが取得できなければ何もしない
		NAGI_PRINT("map_num debug menu crate failed\n");
		return;
	}
	memset(wp,0,sizeof(DEBUG_WINDOW_DATA));


	//デバッグメニュー用変数初期化
	InitDebugWindow(wp);

	//メイン処理タスク追加
	pTcb = TCB_Add(DebugListControlTask,wp,0);


	wp->ld = BMP_MENULIST_Create( inNum, HEAPID_FIELD );
	{
		MSGDATA_MANAGER* msgman;
		int i;

		msgman = MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_nagi_dat, HEAPID_FIELD);
		for(i=0; i<inNum; i++)
		{
			BMP_MENULIST_AddArchiveString( wp->ld, msgman,
					list[i].str_id, list[i].param );
		}
		MSGMAN_Delete(msgman);
	}

	//BITMAPメニュー追加
	GF_BGL_BmpWinAddEx(sp_fldsys->bgl,&wp->win,win_dat);
	//BMPリスト設定
	bmplist_h.count = inNum;
	if (9 < inNum){
		bmplist_h.line = 9;
	}else{
		bmplist_h.line = inNum;
	}
	NAGI_PRINT("disp=%d\n",inNum);
	bmplist_h.list = wp->ld;
	bmplist_h.win = &wp->win;
	wp->lw = BmpListSet(&bmplist_h,wp->debug_list,wp->debug_cursor,HEAPID_FIELD);
	//イベントフック
	FieldSystemProc_SeqHold();
	return;
}

//1行動くごとのコールバック
static void	MoveLineCallBack(BMPLIST_WORK* lw,u32 param,u8 y)
{
	if(param == BMPLIST_RABEL){
		BmpListTmpColorChange(lw,FBMP_COL_GRN_SDW,FBMP_COL_BLACK,FBMP_COL_GREEN);
	}else{
		BmpListTmpColorChange(lw,FBMP_COL_WHITE,FBMP_COL_BLACK,FBMP_COL_BLK_SDW);
	}
}

//===============================================================================
//	ウィンドウ共通
//===============================================================================
//初期化
static void InitDebugWindow(DEBUG_WINDOW_DATA *wp)
{
	wp->debug_list = 0;
	wp->debug_cursor = 1;	//	0番がラベルのため
}
//リストの開放処理
static void DebugListFree(TCB_PTR tcb,void* work)
{
	DEBUG_WINDOW_DATA	*wp;

	wp = (DEBUG_WINDOW_DATA*)work;

	//BMPウィンドウOFF
	GF_BGL_BmpWinOff(&wp->win);

	//BMPリスト破棄
	BmpListExit( wp->lw,&wp->debug_list,&wp->debug_cursor );
	//BMPWindow消去
	GF_BGL_BmpWinDel( &wp->win );
	return;
}
//デバッグウィンドウを解放
static void FreeDebugWindow(TCB_PTR tcb,void* work)
{
	//リストの開放処理
	DebugListFree(tcb,work);
	//ワークメモリ開放
	sys_FreeMemoryEz(work);
}

//デバッグウィンドウ終了
static void DebugWindowExit(TCB_PTR tcb,void* work)
{
	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//タスク消去
	TCB_Delete(tcb);
	//OBJ等の動作停止解除
	FieldSystemProc_SeqHoldEnd();//OBJ等の動作停止解除
	return;
}
//リストコントロール
static void DebugListControlTask(TCB_PTR tcb,void* work)
{
	s32	ret_code;
	TCB_FUNC	func;
	DEBUG_WINDOW_DATA	*wp;

	wp = (DEBUG_WINDOW_DATA*)work;

	ret_code = BmpListMain(wp->lw);
	//キー操作判定
	if(sys.trg & PAD_BUTTON_A){
		if(ret_code){
			BMP_MENULIST_Delete( wp->ld );
			func = (TCB_FUNC)ret_code;
			func(tcb,work);

			//	前の命令保存
			SetPreCommand( func );
		}
		return;
	}
	//メニューキャンセル
	if(sys.trg & PAD_BUTTON_B){
		BMP_MENULIST_Delete( wp->ld );
		DebugWindowExit(tcb,work);
		return;
	}
}
// 文字表示用BMPWIN作成
static void MakeBmpWin( GF_BGL_BMPWIN *p_bmpwin, const BMPWIN_DAT *p_dat )
{
	//	BG面設定
/*	GF_BGL_BGControlExit( sp_fldsys->bgl, p_dat->frm_num );
	{	// SUB DISP BG1
		static const GF_BGL_BGCNT_HEADER SBg1_Data = {
			0, 0, 0x800, 0,
			GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x4000, GX_BG_CHARBASE_0x00000,
			GX_BG_EXTPLTT_01, 0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( sp_fldsys->bgl, p_dat->frm_num, &SBg1_Data, GF_BGL_MODE_TEXT );
	}
*/
	//	BMPWIN作成
#if 0
	p_bmpwin	= GF_BGL_BmpWinAllocGet(HEAPID_FIELD, 1);
	GF_BGL_BmpWinAdd(sp_fldsys->bgl, p_bmpwin, p_dat->frm_num, p_dat->pos_x, p_dat->pos_y, p_dat->siz_x, p_dat->siz_y, p_dat->palnum, p_dat->chrnum );
#else
	GF_BGL_BmpWinAddEx( sp_fldsys->bgl, p_bmpwin, p_dat );
	GF_BGL_BmpWinDataFill( p_bmpwin, FBMP_COL_WHITE );
	GF_BGL_BmpWinOn( p_bmpwin );
#endif

	//	BMPWIN設定
	GF_BGL_PrioritySet( p_dat->frm_num, 0 );
	GF_Disp_GX_VisibleControl( p_dat->frm_num, VISIBLE_ON );
}
static void EndBmpWin( GF_BGL_BMPWIN *p_bmpwin )
{
//	GF_BGL_BGControlExit( sp_fldsys->bgl, GF_BGL_BmpWinGet_Frame( p_bmpwin ) );

	GF_BGL_BmpWinOff( p_bmpwin );
	//	BMP破棄
	GF_BGL_BmpWinDel( p_bmpwin );
}

static void PrintStrBmpWin( GF_BGL_BMPWIN* win, const DEBUG_BMPWIN_STRPRINT_TBL *p_tbl )
{
	int i	= 0;
	STRBUF* str;
	MSGDATA_MANAGER* msgman	= MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_nagi_dat, HEAPID_FIELD);
	while( p_tbl[i].str_id != DEBUG_BMPWIN_STRPRINT_END ) {
		str	= MSGMAN_AllocString( msgman, p_tbl[i].str_id );
		GF_STR_PrintSimple( win, FONT_SYSTEM, str, p_tbl[i].x, p_tbl[i].y, 0, NULL );
		STRBUF_Delete( str );
		i++;
	}
	MSGMAN_Delete(msgman);

	GF_BGL_BmpWinOn( win );
}

static void PrintNumBmpWin( GF_BGL_BMPWIN* win, s32 num, u32 x, u32 y )
{
	STRBUF* str = STRBUF_Create(12, HEAPID_FIELD);
	STRBUF_SetNumber( str, num, 10, NUMBER_DISPTYPE_SPACE, NUMBER_CODETYPE_DEFAULT );
	GF_STR_PrintSimple(win, FONT_SYSTEM, str, x, y, 0, NULL );
	STRBUF_Delete(str);
}

static void ClearRangeBmpWin( GF_BGL_BMPWIN* win, u32 x, u32 y  )
{
	STRBUF* str;
	MSGDATA_MANAGER* msgman	= MSGMAN_Create(MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_debug_nagi_dat, HEAPID_FIELD);
	str	= MSGMAN_AllocString( msgman, MSG_SPACELINE );
	GF_STR_PrintSimple( win, FONT_SYSTEM, str, x, y, 0, NULL );
	STRBUF_Delete( str );
	MSGMAN_Delete(msgman);
}

//-----------------------------------------------------------------------------
/**
 *		曲と同期
 */
//-----------------------------------------------------------------------------
static const struct {
	s16	x;
	s16	y;
} STRPOS_TBL[]	= {
	{ 100, 5*16},
	{ 100, 6*16},
	{ 100, 7*16},
	{ 100, 8*16},
	{ 100, 9*16},
};
static void StartBgmTiming( TCB_PTR p_tcb, void * p_work )
{
	D_NAGI_BGMSYNC_WORK* p_data;

	p_data = sys_AllocMemory( HEAPID_FIELD, sizeof(D_NAGI_BGMSYNC_WORK) );
	memset( p_data, 0, sizeof(D_NAGI_BGMSYNC_WORK) );

	p_data->sync_no	= 0;
	p_data->bgm_no	= SEQ_GS_VS_ROCKET;	//	デフォルト
	p_data->array_no= 0;

	//	ウィンドウを消す
	FreeDebugWindow(p_tcb,p_work);
	//	ウィンドウ操作TCBを消す
	TCB_Delete(p_tcb);

	MakeBmpWin( &p_data->bmpwin, &BgmSyncDebugStrWindowData );
	PrintStrBmpWin( &p_data->bmpwin, BgmSyncDebugStr );

	PrintNumBmpWin( &p_data->bmpwin, p_data->sync_no, STRPOS_TBL[0].x, STRPOS_TBL[0].y  );
	PrintNumBmpWin( &p_data->bmpwin, p_data->bgm_no, STRPOS_TBL[1].x, STRPOS_TBL[1].y  );
	PrintNumBmpWin( &p_data->bmpwin, p_data->array_no, STRPOS_TBL[2].x, STRPOS_TBL[2].y );

	TCB_Add( MainBgmTiming, p_data, 0 );
}

static void MainBgmTiming( TCB_PTR p_tcb, void * p_work )
{
	s16 ret	= -1;
	u8	player_no;
	D_NAGI_BGMSYNC_WORK* p_data	= p_work;

	//	再生開始
	if( sys.trg & PAD_BUTTON_A ) {
		Snd_Stop();
		if( !Snd_BgmPlay(p_data->bgm_no ) ) {
			OS_Printf( "曲が再生されなかった\n" );
		}

		p_data->is_bgmplay	= 1;
		p_data->sync_no		= 0;
	}
	//	停止
	else if ( sys.trg & PAD_BUTTON_B ) {
		Snd_Stop();
		p_data->is_bgmplay	= 0;
	}
	//	強制終了
	else if( sys.trg & PAD_BUTTON_Y ){
		EndBmpWin( &p_data->bmpwin );
		sys_FreeMemoryEz( p_work );
		TCB_Delete( p_tcb );
		FieldSystemProc_SeqHoldEnd();
	}
	else if ( sys.trg & PAD_BUTTON_X ) {
		{
			u8 player_no			= Snd_GetPlayerNo( p_data->bgm_no );
			int handle_no			= Snd_GetHandleNoByPlayerNo( player_no );
			NNSSndHandle *p_handle	= Snd_HandleGet( handle_no );
			SNDPlayerInfo	playerinfo;
			if( NNS_SndPlayerReadDriverPlayerInfo( p_handle, &playerinfo ) ) {
				NAGIHASHI_PRINT( "●PLAYER_INFO\ntemp:%d\nvolume:\n", playerinfo.tempo, playerinfo.volume );
			}else{
				NAGIHASHI_PRINT( "●PLAYER_INFO\nfailed:\n" );
			}
		}
	}


	//	曲情報変更
	//	上下は変数変更
	//	左右はシーケンス変更
	//	LRはサウンドシーン変更→いらなくなった。
	//
	if( sys.trg & PAD_KEY_UP) {
		p_data->array_no++;
		p_data->array_no	= NAGI_ROUND(p_data->array_no, 0, 15 );
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[2].x, STRPOS_TBL[2].y );
		PrintNumBmpWin( &p_data->bmpwin, p_data->array_no, STRPOS_TBL[2].x, STRPOS_TBL[2].y  );
	}else if ( sys.trg & PAD_KEY_DOWN ) {
		p_data->array_no--;
		p_data->array_no	= NAGI_ROUND(p_data->array_no, 0, 15 );
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[2].x, STRPOS_TBL[2].y );
		PrintNumBmpWin( &p_data->bmpwin, p_data->array_no, STRPOS_TBL[2].x, STRPOS_TBL[2].y );
	}else if( sys.trg & PAD_KEY_LEFT) {
		p_data->bgm_no--;
		p_data->bgm_no	= NAGI_ROUND(p_data->bgm_no, SEQ_DUMMY, SEQ_BGM_END );
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[1].x, STRPOS_TBL[1].y );
		PrintNumBmpWin( &p_data->bmpwin, p_data->bgm_no, STRPOS_TBL[1].x, STRPOS_TBL[1].y  );

		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[3].x, STRPOS_TBL[3].y );
	}else if ( sys.trg & PAD_KEY_RIGHT ) {
		p_data->bgm_no++;
		p_data->bgm_no	= NAGI_ROUND(p_data->bgm_no, SEQ_DUMMY, SEQ_BGM_END );
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[1].x, STRPOS_TBL[1].y );
		PrintNumBmpWin( &p_data->bmpwin, p_data->bgm_no, STRPOS_TBL[1].x, STRPOS_TBL[1].y  );

		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[3].x, STRPOS_TBL[3].y );
	}

	//	曲を調べる
	if( Snd_ReadVariableByBgmNo( p_data->bgm_no, p_data->array_no, &ret ) ) {
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[3].x, STRPOS_TBL[3].y );
		PrintNumBmpWin( &p_data->bmpwin, ret, STRPOS_TBL[3].x, STRPOS_TBL[3].y  );
	}

	if( p_data->is_bgmplay ){
		p_data->sync_no++;
		//	シンク
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[0].x, STRPOS_TBL[0].y );
		PrintNumBmpWin( &p_data->bmpwin, p_data->sync_no, STRPOS_TBL[0].x, STRPOS_TBL[0].y  );

		//	チック
		ClearRangeBmpWin( &p_data->bmpwin, STRPOS_TBL[4].x, STRPOS_TBL[4].y );
		PrintNumBmpWin( &p_data->bmpwin, Snd_PlayerGetTick(  Snd_GetPlayerNo(p_data->bgm_no) ), STRPOS_TBL[4].x, STRPOS_TBL[4].y  );
	}
}

//-----------------------------------------------------------------------------
/**
 *		手書き再現、データ化
 */
//-----------------------------------------------------------------------------
static void StartHandDraw( TCB_PTR p_tcb, void* p_work )
{
	D_NAGI_HANDDRAW_WORK* p_data;

	p_data = sys_AllocMemory( HEAPID_FIELD, sizeof(D_NAGI_HANDDRAW_WORK) );
	memset( p_data, 0, sizeof(D_NAGI_HANDDRAW_WORK) );

	//	ウィンドウを消す
	FreeDebugWindow(p_tcb,p_work);
	//	ウィンドウ操作TCBを消す
	TCB_Delete(p_tcb);

	MakeBmpWin( &p_data->bmpwin, &BgmSyncDebugStrWindowData );
	PrintStrBmpWin( &p_data->bmpwin, HandDrawDebugStr );

	TCB_Add( MainHandDraw, p_data, 0 );

}

static void MainHandDraw( TCB_PTR p_tcb, void* p_work )
{
	D_NAGI_HANDDRAW_WORK* p_data	= p_work;

	switch( p_data->seq ) {
	case 0:
		if( sys.trg & PAD_BUTTON_A ) {
//			StartEncountEffectSys( ENCOUNT_TEST );
			StartEncountEffectSys( ENCOUNT_OLD );
		}

		if( sys.tp_trg ) {
			OS_Printf( "▼ここから-------\n" );
			OS_Printf("static const ENC_HAND_DRAW_POS_TBL enc_draw_pos_tbl[] = {\n" );
			p_data->seq	= 1;
			p_data->idx	= 0;
		}
		break;

	case 1:
		if( sys.cont & PAD_KEY_UP || sys.cont & PAD_BUTTON_X ) {
			if( sys.tp_trg ) {
				OS_TPrintf( "	{ %d, %d},\n", sys.tp_x, sys.tp_y );
				g_debug_enc_draw_pos_tbl[p_data->idx].x	= sys.tp_x;
				g_debug_enc_draw_pos_tbl[p_data->idx].y	= sys.tp_y;
				p_data->idx++;
				p_data->idx	= MATH_CLAMP( p_data->idx, 0, HAND_DRAW_TBL_MAX-1 );

			}
		}else{
			if( sys.tp_cont == 0 ) {
				if( !(sys.cont & PAD_BUTTON_L || sys.cont & PAD_BUTTON_R) ) {
					OS_Printf( "	{ ENC_HAND_DRAW_POS_TBL_END, ENC_HAND_DRAW_POS_TBL_END },\n" );
					OS_Printf("};\n" );
					OS_Printf( "▲ここまで-------\n" );
					p_data->seq = 0;

					g_debug_enc_draw_pos_tbl[p_data->idx].x	= ENC_HAND_DRAW_POS_TBL_END;
					g_debug_enc_draw_pos_tbl[p_data->idx].y	= ENC_HAND_DRAW_POS_TBL_END;
				}
			}else{

				OS_TPrintf( "	{ %d, %d},\n", sys.tp_x, sys.tp_y );
				g_debug_enc_draw_pos_tbl[p_data->idx].x	= sys.tp_x;
				g_debug_enc_draw_pos_tbl[p_data->idx].y	= sys.tp_y;
				p_data->idx++;
				p_data->idx	= MATH_CLAMP( p_data->idx, 0, HAND_DRAW_TBL_MAX-1 );
			}
		}
		break;
	}


	if( sys.trg & PAD_BUTTON_Y ){
		EndBmpWin( &p_data->bmpwin );
		sys_FreeMemoryEz( p_work );
		TCB_Delete( p_tcb );
		FieldSystemProc_SeqHoldEnd();
	}

}
//-----------------------------------------------------------------------------
/**
 *		ステージ変移
 */
//-----------------------------------------------------------------------------

#include "frontier/frontier_types.h"
#include "frontier/frontier_main.h"
#include "frontier/fss_scene.h"
static void FrontierStage_SetProc( void *p_wk_adrs )
{

	FRONTIER_EX_PARAM* ex_param = sys_AllocMemoryLo( HEAPID_BASE_DEBUG, sizeof(FRONTIER_EX_PARAM) );
	MI_CpuClear8( ex_param, sizeof(FRONTIER_EX_PARAM) );

	//ex_param作成
	ex_param->syswork		= NULL;
	ex_param->config		= SaveData_GetConfig( sp_fldsys->savedata );
	ex_param->scene_id		= FSS_SCENEID_STAGE_START;
	ex_param->savedata		= sp_fldsys->savedata;
	ex_param->zone_id		= sp_fldsys->location->zone_id;
	ex_param->bag_cursor	= sp_fldsys->bag_cursor;
	ex_param->battle_cursor = sp_fldsys->battle_cursor;

	GameSystem_StartSubProc( sp_fldsys, &FrontierMainProcData, ex_param );
}

static void CallFrontierStage( TCB_PTR tcb,void* work )
{
	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//タスク消去
	TCB_Delete(tcb);

	//	Frontierはフィールドシステムがおわるので

	{
		D_NAGI_APPLICATION_WORK*	p_app_wk;
		p_app_wk	= APPLICATION_AllocWork( HEAPID_BASE_DEBUG, 0 );
		p_app_wk->SetProcFunction	= FrontierStage_SetProc;
		TCB_Add(DebugNagi_CallApplication, p_app_wk, 0);
	}
}

//-----------------------------------------------------------------------------
/*
	キャッスル

	d_nakahiro.cがオーバーレイ化されているので、間借りします。
	2008/11/06 by nakahiro
*/
//-----------------------------------------------------------------------------
//#include "../frontier/castle_tool.h"
//static CASTLE_SCRWORK castle_test;

static void FrontierCastle_SetProc( void *p_wk_adrs )
{
	FRONTIER_EX_PARAM* ex_param = sys_AllocMemoryLo( HEAPID_BASE_DEBUG, sizeof(FRONTIER_EX_PARAM) );
	MI_CpuClear8( ex_param, sizeof(FRONTIER_EX_PARAM) );

	//ex_param作成
//	ex_param->syswork		= &castle_test;
	ex_param->syswork		= NULL;
	ex_param->config		= SaveData_GetConfig( sp_fldsys->savedata );
	ex_param->scene_id		= FSS_SCENEID_CASTLE_START;
	ex_param->savedata		= sp_fldsys->savedata;
	ex_param->zone_id		= sp_fldsys->location->zone_id;
	ex_param->bag_cursor	= sp_fldsys->bag_cursor;
	ex_param->battle_cursor = sp_fldsys->battle_cursor;
/*
	// castle_test
	MI_CpuClear8( &castle_test, sizeof(CASTLE_SCRWORK) );
	castle_test.type = 0;
	castle_test.p_m_party = SaveData_GetTemotiPokemon( sp_fldsys->savedata );
	castle_test.p_e_party = SaveData_GetTemotiPokemon( sp_fldsys->savedata );
	castle_test.pair_cp = 0;
	castle_test.mine_poke_pos[0] = 0;
	castle_test.mine_poke_pos[1] = 1;
	castle_test.mine_poke_pos[2] = 2;
*/
/*
	//情報が公開されたかフラグ
	for( i=0; i < CASTLE_ENEMY_POKE_MAX ;i++ ){
		castle_call->enemy_temoti_flag[i]	= bc_scr_wk->enemy_temoti_flag[i];
		castle_call->enemy_level_flag[i]	= bc_scr_wk->enemy_level_flag[i];
		castle_call->enemy_tuyosa_flag[i]	= bc_scr_wk->enemy_tuyosa_flag[i];
		castle_call->enemy_waza_flag[i]		= bc_scr_wk->enemy_waza_flag[i];
	}
*/

	GameSystem_StartSubProc( sp_fldsys, &FrontierMainProcData, ex_param );

/*
static void CastleCallWorkSet( CASTLE_CALL_WORK* castle_call, CASTLE_SCRWORK* bc_scr_wk )
{
	int i;

	castle_call->type			= bc_scr_wk->type;
//	castle_call->level			= bc_scr_wk->level;
//	castle_call->mode			= CASTLE_MODE_RENTAL;
	castle_call->p_m_party		= bc_scr_wk->p_m_party;
	castle_call->p_e_party		= bc_scr_wk->p_e_party;
	castle_call->p_work			= bc_scr_wk;
	castle_call->pair_cp		= bc_scr_wk->pair_cp;

	//情報が公開されたかフラグ
	for( i=0; i < CASTLE_ENEMY_POKE_MAX ;i++ ){
		castle_call->enemy_temoti_flag[i]	= bc_scr_wk->enemy_temoti_flag[i];
		castle_call->enemy_level_flag[i]	= bc_scr_wk->enemy_level_flag[i];
		castle_call->enemy_tuyosa_flag[i]	= bc_scr_wk->enemy_tuyosa_flag[i];
		castle_call->enemy_waza_flag[i]		= bc_scr_wk->enemy_waza_flag[i];
	}

	return;
}
*/

}

static void CallFrontierCastle( TCB_PTR tcb,void* work )
{
	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//タスク消去
	TCB_Delete(tcb);

	//	Frontierはフィールドシステムがおわるので

	{
		D_NAGI_APPLICATION_WORK*	p_app_wk;
		p_app_wk	= APPLICATION_AllocWork( HEAPID_BASE_DEBUG, 0 );
		p_app_wk->SetProcFunction	= FrontierCastle_SetProc;
		TCB_Add(DebugNagi_CallApplication, p_app_wk, 0);
	}
}

//-----------------------------------------------------------------------------
/*
	ファクトリー

	d_nakahiro.cがオーバーレイ化されているので、間借りします。
	2008/11/25 by nakahiro
*/
//-----------------------------------------------------------------------------
#if 0
#include "application/factory.h"
#include "../frontier/factory_tool.h"

typedef struct {
	FACTORY_CALL_WORK	call_work;
	FRONTIER_EX_PARAM	ex_param;
	FACTORY_SCRWORK		scr_wk;

	SET_PROC_FUNCTION	func;
	u32	seq;
}D_FACTORY_WORK;
#endif


static void FrontierFactory_SetProc( void * p_wk_adrs )
{
	//オーバーレイID宣言
	FS_EXTERN_OVERLAY( factory );

	//ファクトリープロセスデータ
	static const PROC_DATA FactoryProc = {
		FactoryProc_Init,
		FactoryProc_Main,
		FactoryProc_End,
		FS_OVERLAY_ID( factory ),
	};

	D_FACTORY_WORK * wk;

	wk = p_wk_adrs;

	GameSystem_StartSubProc( sp_fldsys, &FactoryProc, &wk->call_work );
}

static void CallFrontierFactoryR( TCB_PTR tcb, void * work )
{
	D_FACTORY_WORK * wk;

	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//タスク消去
	TCB_Delete(tcb);

	//	Frontierはフィールドシステムがおわるので

	wk = sys_AllocMemoryLo( HEAPID_BASE_DEBUG, sizeof(D_FACTORY_WORK) );
	MI_CpuClear8( wk, sizeof(D_FACTORY_WORK) );
	wk->fsys = sp_fldsys;

	//ex_param作成
//	wk->ex_param.syswork       = &castle_test;
	wk->ex_param.syswork       = NULL;
	wk->ex_param.config        = SaveData_GetConfig( sp_fldsys->savedata );
	wk->ex_param.scene_id      = FSS_SCENEID_FACTORY;
	wk->ex_param.savedata      = sp_fldsys->savedata;
	wk->ex_param.zone_id       = sp_fldsys->location->zone_id;
	wk->ex_param.bag_cursor    = sp_fldsys->bag_cursor;
	wk->ex_param.battle_cursor = sp_fldsys->battle_cursor;

/*
//ファクトリーのゲームレベル
#define FACTORY_LEVEL_50		(0)							//レベル50
#define FACTORY_LEVEL_OPEN		(1)							//オープン
#define FACTORY_LEVEL_MAX		(2)							//最大数

//タイプ
#define FACTORY_TYPE_SINGLE		(0)
#define FACTORY_TYPE_DOUBLE		(1)
#define FACTORY_TYPE_MULTI		(2)
#define FACTORY_TYPE_WIFI_MULTI	(3)
#define FACTORY_TYPE_MAX		(4)							//最大数

//モード
#define FACTORY_MODE_RENTAL		(0)							//レンタル
#define FACTORY_MODE_TRADE		(1)							//交換

//ポケモン数
#define FACTORY_RENTAL_POKE_MAX	(6)							//レンタルポケモンデータの最大数
#define FACTORY_MINE_POKE_MAX	(4)							//味方ポケモンデータの最大数
#define FACTORY_ENEMY_POKE_MAX	(4)							//敵ポケモンデータの最大数
#define FACTORY_TOTAL_POKE_MAX	(FACTORY_MINE_POKE_MAX+FACTORY_ENEMY_POKE_MAX)	//被りチェックに使用
*/

	wk->call_work.sv		= wk->ex_param.savedata;
	wk->call_work.type		= FACTORY_TYPE_SINGLE;
	wk->call_work.level		= FACTORY_LEVEL_50;
	wk->call_work.mode		= FACTORY_MODE_RENTAL;
	wk->call_work.p_m_party	= SaveData_GetTemotiPokemon(sp_fldsys->savedata);
	wk->call_work.p_e_party	= SaveData_GetTemotiPokemon(sp_fldsys->savedata);
	wk->call_work.p_work	= &wk->scr_wk;

	wk->func = FrontierFactory_SetProc;

	TCB_Add( DebugNagi_FactoryTask, wk, 0 );
}

static void CallFrontierFactoryC( TCB_PTR tcb, void * work )
{
	D_FACTORY_WORK * wk;

	//ウィンドウ解放
	FreeDebugWindow(tcb,work);
	//タスク消去
	TCB_Delete(tcb);

	//	Frontierはフィールドシステムがおわるので

	wk = sys_AllocMemoryLo( HEAPID_BASE_DEBUG, sizeof(D_FACTORY_WORK) );
	MI_CpuClear8( wk, sizeof(D_FACTORY_WORK) );
	wk->fsys = sp_fldsys;

	//ex_param作成
//	wk->ex_param.syswork       = &castle_test;
	wk->ex_param.syswork       = NULL;
	wk->ex_param.config        = SaveData_GetConfig( sp_fldsys->savedata );
	wk->ex_param.scene_id      = FSS_SCENEID_FACTORY;
	wk->ex_param.savedata      = sp_fldsys->savedata;
	wk->ex_param.zone_id       = sp_fldsys->location->zone_id;
	wk->ex_param.bag_cursor    = sp_fldsys->bag_cursor;
	wk->ex_param.battle_cursor = sp_fldsys->battle_cursor;

	wk->call_work.sv		= wk->ex_param.savedata;
	wk->call_work.type		= FACTORY_TYPE_SINGLE;
	wk->call_work.level		= FACTORY_LEVEL_50;
	wk->call_work.mode		= FACTORY_MODE_TRADE;
	wk->call_work.p_m_party	= SaveData_GetTemotiPokemon(sp_fldsys->savedata);;
	wk->call_work.p_e_party	= SaveData_GetTemotiPokemon(sp_fldsys->savedata);;
	wk->call_work.p_work	= &wk->scr_wk;

	wk->func = FrontierFactory_SetProc;

	TCB_Add( DebugNagi_FactoryTask, wk, 0 );
}


//-----------------------------------------------------------------------------
/*
	フロンティア成績画面

	d_nakahiro.cがオーバーレイ化されているので、間借りします。
	2008/12/11 by nakahiro
*/
//-----------------------------------------------------------------------------
/*
#include "application/frontier_monitor.h"
BOOL DEBUG_FrontierMonitorEvent( GMEVENT_CONTROL * event );
BOOL DEBUG_FrontierMonitorEvent( GMEVENT_CONTROL * event )
{
	FIELDSYS_WORK * fsys;
	D_FM_WORK * wk;

	fsys = FieldEvent_GetFieldSysWork( event );
	wk   = FieldEvent_GetSpecialWork( event );

	switch( wk->seq ){
	case 0:
		if( WIPE_SYS_EndCheck() ){
			FieldSystemProc_SeqHoldEnd();
			FieldOBJSys_MoveStopAll( fsys->fldobjsys );
//			WazaOshie_ProcSet( fsys , &wk->dat );
			wk->dat = FrontierMonitor_SetProc( fsys, wk->type, wk->fr_no, wk->monsno, HEAPID_BASE_DEBUG );
			wk->seq = 1;
		}
		break;

	case 1:
		if( !( FieldEvent_Cmd_WaitSubProcEnd(fsys) ) ) {
			FieldEvent_Cmd_SetMapProc( fsys );
			wk->seq = 2;
		}
		break;

	case 2:
		if( FieldEvent_Cmd_WaitMapProcStart( fsys ) ){
			FieldFadeWipeSet( FLD_DISP_BRIGHT_BLACKIN );
			wk->seq = 3;
		}
		break;

	case 3:
		if( WIPE_SYS_EndCheck() ){
			sys_FreeMemoryEz( wk->dat );
			sys_FreeMemoryEz( wk );
			FieldOBJSys_MoveStopAllClear( fsys->fldobjsys );
			return TRUE;
		}
	}
	return FALSE;
}

BOOL DEBUG_BattleTowerAppEvent( GMEVENT_CONTROL * event );
BOOL DEBUG_BattleTowerAppEvent( GMEVENT_CONTROL * event )
{
	FIELDSYS_WORK * fsys;
	D_BTAPP_WORK * wk;

	fsys = FieldEvent_GetFieldSysWork( event );
	wk   = FieldEvent_GetSpecialWork( event );

	switch( wk->seq ){
	case 0:
		if( WIPE_SYS_EndCheck() ){
			FieldSystemProc_SeqHoldEnd();
			FieldOBJSys_MoveStopAll( fsys->fldobjsys );
			BTowerApp_SetProc( fsys, wk->dat );
//			WazaOshie_ProcSet( fsys , &wk->dat );
//			wk->dat = FrontierMonitor_SetProc( fsys, wk->type, wk->fr_no, wk->monsno, HEAPID_BASE_DEBUG );
			wk->seq = 1;
		}
		break;

	case 1:
		if( !( FieldEvent_Cmd_WaitSubProcEnd(fsys) ) ) {
			FieldEvent_Cmd_SetMapProc( fsys );
			wk->seq = 2;
		}
		break;

	case 2:
		if( FieldEvent_Cmd_WaitMapProcStart( fsys ) ){
			FieldFadeWipeSet( FLD_DISP_BRIGHT_BLACKIN );
			wk->seq = 3;
		}
		break;

	case 3:
		if( WIPE_SYS_EndCheck() ){
			sys_FreeMemoryEz( wk->dat );
			sys_FreeMemoryEz( wk );
			FieldOBJSys_MoveStopAllClear( fsys->fldobjsys );
			return TRUE;
		}
	}
	return FALSE;
}
*/

#if 0
//-----------------------------------------------------------------------------
/*
	伝説デモ

	d_nakahiro.cがオーバーレイ化されているので、間借りします。
	2008/12/11 by nakahiro
*/
//-----------------------------------------------------------------------------
#include "demo/legend_demo.h"

BOOL DEBUG_LegendDemoMain( GMEVENT_CONTROL * event );
BOOL DEBUG_LegendDemoMain( GMEVENT_CONTROL * event )
{
	FIELDSYS_WORK * fsys;
	D_LD_WORK * wk;

	fsys = FieldEvent_GetFieldSysWork( event );
	wk   = FieldEvent_GetSpecialWork( event );

	switch( wk->seq ){
	case 0:
		if( WIPE_SYS_EndCheck() ){
			FieldSystemProc_SeqHoldEnd();
			FieldOBJSys_MoveStopAll( fsys->fldobjsys );
//			WazaOshie_ProcSet( fsys , &wk->dat );
			wk->dat = LegendDemo_SetProc( fsys, fsys->glst_data, wk->mode, wk->time, HEAPID_BASE_DEBUG );
			wk->dat->scene = wk->scene;
			wk->dat->debug = 1;
			wk->seq = 1;
		}
		break;

	case 1:
		if( !( FieldEvent_Cmd_WaitSubProcEnd(fsys) ) ) {
			FieldEvent_Cmd_SetMapProc( fsys );
			wk->seq = 2;
		}
		break;

	case 2:
		if( FieldEvent_Cmd_WaitMapProcStart( fsys ) ){
			FieldFadeWipeSet( FLD_DISP_BRIGHT_BLACKIN );
			wk->seq = 3;
		}
		break;

	case 3:
		if( WIPE_SYS_EndCheck() ){
			sys_FreeMemoryEz( wk->dat );
			sys_FreeMemoryEz( wk );
			FieldOBJSys_MoveStopAllClear( fsys->fldobjsys );
			return TRUE;
		}
	}
	return FALSE;
}

//-----------------------------------------------------------------------------
/*
	メールボックス

	d_nakahiro.cがオーバーレイ化されているので、間借りします。
	2009/01/31 by nakahiro
*/
//-----------------------------------------------------------------------------
#include "application/mailbox.h"

BOOL DEBUG_MailBoxMain( GMEVENT_CONTROL * event );
BOOL DEBUG_MailBoxMain( GMEVENT_CONTROL * event )
{
	FIELDSYS_WORK * fsys;
	DEBUG_MB_WORK * wk;

	fsys = FieldEvent_GetFieldSysWork( event );
	wk   = FieldEvent_GetSpecialWork( event );

	switch( wk->seq ){
	case 0:
		if( WIPE_SYS_EndCheck() ){
			FieldSystemProc_SeqHoldEnd();
			FieldOBJSys_MoveStopAll( fsys->fldobjsys );
			wk->dat = FieldMailBox_SetProc( fsys, HEAPID_BASE_DEBUG );
			wk->seq = 1;
		}
		break;

	case 1:
		if( !( FieldEvent_Cmd_WaitSubProcEnd(fsys) ) ) {
			FieldEvent_Cmd_SetMapProc( fsys );
			wk->seq = 2;
		}
		break;

	case 2:
		if( FieldEvent_Cmd_WaitMapProcStart( fsys ) ){
			FieldFadeWipeSet( FLD_DISP_BRIGHT_BLACKIN );
			wk->seq = 3;
		}
		break;

	case 3:
		if( WIPE_SYS_EndCheck() ){
			sys_FreeMemoryEz( wk->dat );
			sys_FreeMemoryEz( wk );
			FieldOBJSys_MoveStopAllClear( fsys->fldobjsys );
			return TRUE;
		}
	}
	return FALSE;
}
#endif

//-----------------------------------------------------------------------------
/**
 *		ワイプ
 */
//-----------------------------------------------------------------------------
static void StartWipe( TCB_PTR tcb,void* work )// 画面切り替え開始
{
	TCB_PTR tcb_ptr;
	D_TMY_WIPE* data;

	tcb_ptr		= PMDS_taskAdd(MainWipe, sizeof(D_TMY_WIPE), 6, HEAPID_FIELD);
	data		= TCB_GetWork(tcb_ptr);
	data->seq	= 0;
	data->no	= 0;

	// フィールドのHブランク処理ストップ
	FLDHBLANK_SYS_Stop( sp_fldsys->fldmap->hblanksys );

	FreeDebugWindow(tcb,work);
	TCB_Delete(tcb);
}

static void MainWipe( TCB_PTR tcb,void* work )// 画面切り替えメイン
{
	D_TMY_WIPE* data = (D_TMY_WIPE*)work;


	// 強制終了
	if( sys.cont & PAD_BUTTON_X ){
		//強制終了
		WIPE_SYS_ExeEnd();

		PMDS_taskDel( tcb );
		// フィールドのHブランク処理開始
		FLDHBLANK_SYS_Start( sp_fldsys->fldmap->hblanksys );
		FieldSystemProc_SeqHoldEnd();
	}

	switch(data->seq){
	case 0:
		// 状態破棄
		WIPE_SYS_Start(WIPE_PATTERN_FSAM,
			data->no, data->no,
			WIPE_FADE_WHITE,
			8,1, HEAPID_FIELD);

		data->seq++;
		break;

	case 1:
		if (WIPE_SYS_EndCheck()) {
			data->seq = 0;

			data->no += 1;

			if( data->no >= WIPE_TYPE_MAX ){
				WIPE_Reset( WIPE_DISP_MAIN );
				WIPE_Reset( WIPE_DISP_SUB );
				PMDS_taskDel( tcb );
				// フィールドのHブランク処理開始
				FLDHBLANK_SYS_Start( sp_fldsys->fldmap->hblanksys );
				FieldSystemProc_SeqHoldEnd();
			}else{
				if( sys.cont & PAD_BUTTON_B ){

					PMDS_taskDel( tcb );
					// フィールドのHブランク処理開始
					FLDHBLANK_SYS_Start( sp_fldsys->fldmap->hblanksys );
					FieldSystemProc_SeqHoldEnd();
				}
			}
		}
		break;
	}
}



//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントエフェクト開始
 */
//-----------------------------------------------------------------------------
static void StartEncountEffectSys( u32 effect_no )
{
	D_NAGI_ENCOUNT_SYS_WORK* p_data;

	p_data = sys_AllocMemory( HEAPID_FIELD, sizeof(D_NAGI_ENCOUNT_SYS_WORK) );
	memset( p_data, 0, sizeof(D_NAGI_ENCOUNT_SYS_WORK) );

	p_data->no		= effect_no;
	p_data->now_bgm	= Snd_NowBgmNoGet();
	Snd_Stop();
	Snd_BgmPlay(SEQ_GS_VS_ROCKET );
	TCB_Add( MainEncountEffectSys, p_data, 0 );
}

//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントエフェクト開始
 *
 *	@param	tcb		TCBワーク
 *	@param	p_work	ワーク
 *
 *	@return	none
 */
//-----------------------------------------------------------------------------
static void MainEncountEffectSys( TCB_PTR tcb, void* p_work )
{
	D_NAGI_ENCOUNT_SYS_WORK* p_data = p_work;

	switch( p_data->seq ){
	case 0:
		p_data->work[0] = GFC_GetCameraDistance( sp_fldsys->camera_ptr );

		EncountEffectLoad( p_data->no );
		EncountEffectStart( p_data->no, sp_fldsys, &p_data->sub_end );
		p_data->seq ++;
		break;

	case 1:
		if( p_data->sub_end ){

			EncountEffectUnload( p_data->no );

			p_data->seq ++;
			//カメラ戻す
			GFC_SetCameraDistance( p_data->work[0], sp_fldsys->camera_ptr );
			G2_SetBG0Offset(0, 0);
			G2_SetBG1Offset(0, 0);
			G2_SetBG2Offset(0, 0);
			G2_SetBG3Offset(0, 0);

			// BGLを再作成
			Fieldmap_BgExit( sp_fldsys->bgl );
			Fieldmap_BgSet( sp_fldsys->bgl );
			FieldMsgPrintInit( PALTYPE_MAIN_BG, MSG_PRINT_INIT_ON );

			GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG0, VISIBLE_ON );
		}
		break;

	case 2:
		// フィールドHブランクOFF
		FLDHBLANK_SYS_Stop( sp_fldsys->fldmap->hblanksys );

		WIPE_SYS_Start( WIPE_PATTERN_WMS,
				WIPE_TYPE_DOORIN,
				WIPE_TYPE_DOORIN,
				WIPE_FADE_OUTCOLOR,
				WIPE_DEF_DIV,
				WIPE_DEF_SYNC,
				HEAPID_FIELD );
		p_data->seq ++;
		break;

	case 3:
		if( WIPE_SYS_EndCheck() ){
			Snd_Stop();
			while( !Snd_BgmPlay( p_data->now_bgm ) );
			sys_FreeMemoryEz( p_data );
			TCB_Delete( tcb );
			// フィールドHブランクON
			FLDHBLANK_SYS_Start( sp_fldsys->fldmap->hblanksys );
		}
		break;
	}
}

//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントエフェクト開始
 */
//-----------------------------------------------------------------------------


//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントエフェクト開始
 *
 *	@param	u32 effect_no	エフェクト番号
 *	@param	end_type		終了時エフェクト番号
 *
 *	@return
 */
//-----------------------------------------------------------------------------
static void StartEncountEffectSysWithFinish( u32 effect_no, EFFECT_END_TYPE end_type )
{
	D_NAGI_ENCOUNT_SYS_WORK* p_data;

	p_data = sys_AllocMemory( HEAPID_FIELD, sizeof(D_NAGI_ENCOUNT_SYS_WORK) );
	memset( p_data, 0, sizeof(D_NAGI_ENCOUNT_SYS_WORK) );

	p_data->no = effect_no;
	p_data->end= end_type;

	p_data->now_bgm	= Snd_NowBgmNoGet();
	Snd_Stop();
	Snd_BgmPlay(SEQ_GS_VS_ROCKET );
	TCB_Add( MainEncountEffectSysWithFinish, p_data, 0 );
}

//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントエフェクト開始TCB
 *
 *	@param	tcb		TCBワーク
 *	@param	p_work	ワーク
 *
 *	@return	none
 */
//-----------------------------------------------------------------------------
static void MainEncountEffectSysWithFinish( TCB_PTR tcb, void* p_work )
{
	D_NAGI_ENCOUNT_SYS_WORK* p_data = p_work;

	switch( p_data->seq ){
	case 0:
		p_data->work[0] = GFC_GetCameraDistance( sp_fldsys->camera_ptr );

		EncountEffectLoad( p_data->no );
		EncountEffectStart( p_data->no, sp_fldsys, &p_data->sub_end );
		p_data->seq ++;
		break;

	case 1:
		if( p_data->sub_end ){

			EncountEffectUnload( p_data->no );

			p_data->seq ++;
			//カメラ戻す
			GFC_SetCameraDistance( p_data->work[0], sp_fldsys->camera_ptr );
			G2_SetBG0Offset(0, 0);
			G2_SetBG1Offset(0, 0);
			G2_SetBG2Offset(0, 0);
			G2_SetBG3Offset(0, 0);

			// BGLを再作成
			Fieldmap_BgExit( sp_fldsys->bgl );
			Fieldmap_BgSet( sp_fldsys->bgl );
			FieldMsgPrintInit( PALTYPE_MAIN_BG, MSG_PRINT_INIT_ON );

			GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG0, VISIBLE_ON );
		}
		break;

	case 2:
		// フィールドHブランクOFF
		FLDHBLANK_SYS_Stop( sp_fldsys->fldmap->hblanksys );
		EffectEndFunc[p_data->end].Init(p_work);

		p_data->seq ++;
		break;

	case 3:
		if( EffectEndFunc[p_data->end].Main(p_work) ){
			Snd_Stop();
			while( !Snd_BgmPlay( p_data->now_bgm ) );
			sys_FreeMemoryEz( p_data );
			TCB_Delete( tcb );
			// フィールドHブランクON
			FLDHBLANK_SYS_Start( sp_fldsys->fldmap->hblanksys );

		}
		break;
	}
}

//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントエフェクト終了
 *
 *	@return
 */
//-----------------------------------------------------------------------------
static void EffectEnd_StartFadeIn( void *p_adrs )
{
	WIPE_SYS_Start( WIPE_PATTERN_WMS,
				WIPE_TYPE_FADEIN,
				WIPE_TYPE_FADEIN,
				WIPE_FADE_OUTCOLOR,
				WIPE_DEF_DIV,
				WIPE_DEF_SYNC,
				HEAPID_FIELD );
}

static BOOL EffectEnd_MainFadeIn( void *p_adrs )
{
	return WIPE_SYS_EndCheck();
}

//----------------------------------------------------------------------------
/**
 *	@brief	エンカウントメニュー
 */
//-----------------------------------------------------------------------------
static void SetEncountDebugWindow(TCB_PTR tcb,void *work)
{
	DEBUG_WINDOW_DATA	* wp;
	wp = (DEBUG_WINDOW_DATA *)work;

	//メインウィンドウを消す
	FreeDebugWindow(tcb,work);
	//メインウィンドウタスク消去
	TCB_Delete(tcb);
	//イベントフック
	FieldSystemProc_SeqHold();


#ifndef GS_DEBUG_OFF
	//エンカウントメニュー構築
	MakeBmpList(NELEMS(SubEncountDebugList),SubEncountDebugList, &EncountDebugListWindowData);
#endif

}

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
static void EncountEffect_Start( TCB_PTR tcb, void* p_work, u32 effect_no )
{
	StartEncountEffectSys( effect_no );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
}

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
static void EncountEffect_StartWithFinish( TCB_PTR tcb, void* p_work,
		u32 effect_no, EFFECT_END_TYPE end_type )
{
	StartEncountEffectSysWithFinish( effect_no, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
}
#ifndef GS_DEBUG_OFF
//----------------------------------------------------------------------------
/**
 *	@brief	草　レベル低
 */
//-----------------------------------------------------------------------------
static void EncountEffect_00( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_FIELD_GRASS_LEVEL_LOW );
#if 0
	StartEncountEffectSys( ENCOUNT_FIELD_GRASS_LEVEL_LOW );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}
//----------------------------------------------------------------------------
/**
 *	@brief	草　レベル高
 */
//-----------------------------------------------------------------------------
static void EncountEffect_01( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_FIELD_GRASS_LEVEL_HIGH );
#if 0
	StartEncountEffectSys( ENCOUNT_FIELD_GRASS_LEVEL_HIGH );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}
//----------------------------------------------------------------------------
/**
 *	@brief	水　レベル低
 */
//-----------------------------------------------------------------------------
static void EncountEffect_02( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_FIELD_WATER_LEVEL_LOW );
#if 0
	StartEncountEffectSys( ENCOUNT_FIELD_WATER_LEVEL_LOW );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}
//----------------------------------------------------------------------------
/**
 *	@brief	水　レベル高
 */
//-----------------------------------------------------------------------------
static void EncountEffect_03( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_FIELD_WATER_LEVEL_HIGH );
#if 0
	StartEncountEffectSys( ENCOUNT_FIELD_WATER_LEVEL_HIGH );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}
//----------------------------------------------------------------------------
/**
 *	@brief	ダンジョン　レベル低
 */
//-----------------------------------------------------------------------------
static void EncountEffect_04( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_FIELD_DAN_LEVEL_LOW );
#if 0
	StartEncountEffectSys( ENCOUNT_FIELD_DAN_LEVEL_LOW );

	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}
//----------------------------------------------------------------------------
/**
 *	@brief	ダンジョン　レベル高
 */
//-----------------------------------------------------------------------------
static void EncountEffect_05( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_FIELD_DAN_LEVEL_HIGH );
#if 0
	StartEncountEffectSys( ENCOUNT_FIELD_DAN_LEVEL_HIGH );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	TRAINER　草　レベル低
 */
//-----------------------------------------------------------------------------
static void EncountEffect_06( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_TRAINER_GRASS_LEVEL_LOW );
#if 0
	StartEncountEffectSys( ENCOUNT_TRAINER_GRASS_LEVEL_LOW );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	TRAINER　草　レベル高
 */
//-----------------------------------------------------------------------------
static void EncountEffect_07( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_TRAINER_GRASS_LEVEL_HIGH );
#if 0
	StartEncountEffectSys( ENCOUNT_TRAINER_GRASS_LEVEL_HIGH );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	TRAINER　水　レベル低
 */
//-----------------------------------------------------------------------------
static void EncountEffect_08( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_TRAINER_WATER_LEVEL_LOW );
#if 0
	StartEncountEffectSys( ENCOUNT_TRAINER_WATER_LEVEL_LOW );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	TRAINER　水　レベル高い
 */
//-----------------------------------------------------------------------------
static void EncountEffect_09( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_TRAINER_WATER_LEVEL_HIGH );
#if 0
	StartEncountEffectSys( ENCOUNT_TRAINER_WATER_LEVEL_HIGH );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	TRAINER　ダン　レベル低
 */
//-----------------------------------------------------------------------------
static void EncountEffect_10( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_TRAINER_DAN_LEVEL_LOW );
#if 0
	StartEncountEffectSys( ENCOUNT_TRAINER_DAN_LEVEL_LOW );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	TRAINER　ダン　レベル高い
 */
//-----------------------------------------------------------------------------
static void EncountEffect_11( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_TRAINER_DAN_LEVEL_HIGH );
#if 0
	StartEncountEffectSys( ENCOUNT_TRAINER_DAN_LEVEL_HIGH );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}


//----------------------------------------------------------------------------
/**
 *	@brief	特殊　バトルタワー　ファクトリー
 */
//-----------------------------------------------------------------------------
static void EncountEffect_12( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPECIAL_TOWER );
#if 0
	StartEncountEffectSys( ENCOUNT_SPECIAL_TOWER );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	特殊	ダブルバトル
 */
//-----------------------------------------------------------------------------
static void EncountEffect_13( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPECIAL_DOUBLE );
#if 0
	StartEncountEffectSys( ENCOUNT_SPECIAL_DOUBLE );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	銀河団　通常
 */
//-----------------------------------------------------------------------------
static void EncountEffect_14( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_NORMAL );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_NORMAL );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	銀河団　幹部
 */
//-----------------------------------------------------------------------------
static void EncountEffect_15( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_RAMUDA );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_RAMUDA );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	伝説ポケモン
 */
//-----------------------------------------------------------------------------
static void EncountEffect_16( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_LEGEND_NORMAL );
#if 0
	StartEncountEffectSys( ENCOUNT_LEGEND_NORMAL );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ルギア
 */
//-----------------------------------------------------------------------------
static void EncountEffect_17( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_LEGEND_RUGIA );
#if 0
	StartEncountEffectSys( ENCOUNT_LEGEND_PACKAGE );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　クロガネ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_18( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_KUROGANE_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_KUROGANE_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　ハクタイ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_19( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_HAKUTAI_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_HAKUTAI_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　ノモセ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_20( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_NOMOSE_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_NOMOSE_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　トバリ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_21( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_TOBARI_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_TOBARI_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　ヨスガ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_22( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_YOSUGA_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_YOSUGA_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　キッサキ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_23( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_KISSAKI_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_KISSAKI_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　ミオ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_24( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_MIO_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_MIO_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム　ナギサ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_25( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_NAGISA_GYM );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_NAGISA_GYM );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList( NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	四天王００
 */
//-----------------------------------------------------------------------------
static void EncountEffect_26( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_SITEN_00 );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_SITEN_00 );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	四天王０１
 */
//-----------------------------------------------------------------------------
static void EncountEffect_27( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_SITEN_01 );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_SITEN_01 );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	四天王02
 */
//-----------------------------------------------------------------------------
static void EncountEffect_28( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_SITEN_02 );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_SITEN_02 );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	四天王03
 */
//-----------------------------------------------------------------------------
static void EncountEffect_29( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_SITEN_03 );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_SITEN_03 );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	チャンピオン
 */
//-----------------------------------------------------------------------------
static void EncountEffect_30( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SPTR_CHANPION );
#if 0
	StartEncountEffectSys( ENCOUNT_SPTR_CHANPION );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 したっぱ 通常(ダミー）
 */
//-----------------------------------------------------------------------------
static void EncountEffect_31( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_NORMAL );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_NORMAL );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 したっぱ 通常
 */
//-----------------------------------------------------------------------------
static void EncountEffect_32( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_NORMAL );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_NORMAL );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 幹部 ラムダ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_33( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_RAMUDA );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_RAMUDA );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 幹部 ランス
 */
//-----------------------------------------------------------------------------
static void EncountEffect_34( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_LANCE );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_LANCE );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 幹部 アポロ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_35( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_APORO );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_APORO );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 幹部 アテナ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_36( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_ATENA );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_ATENA );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	R団 ボス（幹部扱い） サカキ
 */
//-----------------------------------------------------------------------------
static void EncountEffect_37( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_ROCKET_SAKAKI );
#if 0
	StartEncountEffectSys( ENCOUNT_ROCKET_SAKAKI );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	障子
 */
//-----------------------------------------------------------------------------
static void EncountEffect_38( TCB_PTR tcb, void* p_work )
{
	EncountEffect_Start( tcb, p_work, ENCOUNT_SHOJI );
#if 0
	StartEncountEffectSys( ENCOUNT_SHOJI );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	むかし
 */
//-----------------------------------------------------------------------------
static void EncountEffect_39( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_OLD, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_OLD, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	ライバル
 */
//-----------------------------------------------------------------------------
static void EncountEffect_40( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_RIVAL, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_RIVAL, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

//----------------------------------------------------------------------------
/**
 *	@brief	GYMリーダー カントー
 */
//-----------------------------------------------------------------------------
static void EncountEffect_41( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_TAKESHI, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_TAKESHI, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_42( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_KASUMI, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_KASUMI, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_43( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_MATHISU, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_MATHISU, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_44( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_ERIKA, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_ERIKA, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_45( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_ANZU, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_ANZU, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_46( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_NATSUME, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_NATSUME, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_47( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_KATSURA, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_KATSURA, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

static void EncountEffect_48( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_SPTR_GREEN, EFFECT_END_FADEIN );
#if 0
	StartEncountEffectSysWithFinish( ENCOUNT_SPTR_GREEN, EFFECT_END_FADEIN );
	//ウィンドウ解放
	FreeDebugWindow(tcb,p_work);
	//タスク消去
	TCB_Delete(tcb);
	// メインリストセット
	MakeBmpList(  NELEMS(MainDebugList), MainDebugList, &MainDebugListWindowData);
#endif
}

// ホウオウ
static void EncountEffect_49( TCB_PTR tcb, void* p_work )
{
	EncountEffect_StartWithFinish( tcb, p_work, ENCOUNT_LEGEND_HOUOU, EFFECT_END_FADEIN );
}
#endif

//=============================================================================
/**
 *		アプリケーション変移処理
 */
//=============================================================================
//----------------------------------------------------------------------------
/**
 *	@brief	アプリケーション用ワーク作成
 *
 *	@param	heap_id			ヒープID
 *	@param	param_size		サブワークエリア（0で作成しない）
 *
 *	@return	作成したワーク
 */
//-----------------------------------------------------------------------------
static D_NAGI_APPLICATION_WORK* APPLICATION_AllocWork( int heap_id, u32 param_size )
{
	D_NAGI_APPLICATION_WORK* p_wk = sys_AllocMemory( heap_id,sizeof(D_NAGI_APPLICATION_WORK) );
	MI_CpuClear8( p_wk, sizeof(D_NAGI_APPLICATION_WORK) );
	p_wk->seq		= 0;
	p_wk->fsys = sp_fldsys;

	if( param_size ) {
		p_wk->p_param	= sys_AllocMemory( heap_id,param_size );
//		MI_CpuClear8( p_wk, param_size );
		MI_CpuClear8( p_wk->p_param, param_size );	// 09.03.06 fix by hosaka genya
	}
	return p_wk;
}

//-----------------------------------------------------------------------------
/**
 *		マイクテストを呼ぶ
 */
//-----------------------------------------------------------------------------
static void MicTest_SetProc( void * work )
{
	//オーバーレイID定義
	FS_EXTERN_OVERLAY(mictest);

	//オーバーレイプロセス定義データ
	static const PROC_DATA MicTestProcData = {
		MicTestProc_Init,
		MicTestProc_Main,
		MicTestProc_Exit,
		FS_OVERLAY_ID(mictest),
	};
	GameSystem_StartSubProc( sp_fldsys, &MicTestProcData, work );
}
static void CallMicTest( TCB_PTR p_tcb, void *p_wk )
{
	//ウィンドウ解放
	FreeDebugWindow(p_tcb,p_wk);
	//タスク消去
	TCB_Delete(p_tcb);
	{
		D_NAGI_APPLICATION_WORK*	p_app_wk;
		p_app_wk	= APPLICATION_AllocWork( HEAPID_BASE_DEBUG, 0 );
		p_app_wk->SetProcFunction	= MicTest_SetProc;
		TCB_Add(DebugNagi_CallApplication, p_app_wk, 0);
	}
}


//----------------------------------------------------------------------------
/**
 *		前選択したものを起動する
 */
//-----------------------------------------------------------------------------
static void StartPreCommand( TCB_PTR tcb,void* work )
{
	if( sp_PreCommand != NULL ){
		sp_PreCommand( tcb, work );
	}
}

static void SetPreCommand( TCB_FUNC func )
{
	//	再帰をさけるため
	if( func != StartPreCommand ) {
		sp_PreCommand	= func;
	}
}

#endif // PM_DEBUG